package com.jf.blogbackened.bean;

import org.apache.http.HttpStatus;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 结果集
 *
 * @param <T> the type parameter
 */
public class Result<T> extends HashMap<String,Object> implements Serializable {

	private static final long serialVersionUID = 1L;
	private T data;
	private Integer code;

	private String msg;

	public static Result error() {
		return error(50000, "未知异常，请联系管理员");
	}

	public static Result error(String msg) {
		return error(50000, msg);
	}

	public static Result error(int code, String msg) {
		Result r = new Result();
		r.put("code", code);
		r.put("msg", msg);
		return r;
	}

	public static Result ok(String msg) {
		Result r = new Result();
		r.put("code", 20000);
		r.put("msg", msg);
		return r;
	}

	public static Result ok(Map<String, Object> map) {
		Result r = new Result();
		r.putAll(map);
		return r;
	}

	public static Result ok() {
		Result r = new Result();
		r.put("code", 20000);
		r.put("msg", "success");
		return r;
	}

	public Result put(String key, Object value) {
		super.put(key, value);
		return this;
	}

	public Result data(Object value) {
		super.put("data", value);
		return this;
	}


	/**
	 * Gets data.
	 *
	 * @return the data
	 */
	public T getData() {
		return data;
	}

	/**
	 * Sets data.
	 *
	 * @param data the data
	 */
	public void setData(T data) {
		this.data = data;
	}

	/**
	 * Gets code.
	 *
	 * @return the code
	 */
	public Integer getCode() {
		return code;
	}

	/**
	 * Sets code.
	 *
	 * @param code the code
	 */
	public void setCode(Integer code) {
		this.code = code;
	}

	/**
	 * Gets msg.
	 *
	 * @return the msg
	 */
	public String getMsg() {
		return msg;
	}

	/**
	 * Sets msg.
	 *
	 * @param msg the msg
	 */
	public void setMsg(String msg) {
		this.msg = msg;
	}
	
}
